package lazy.libs.utils;

import android.content.Context;

public class UIUtils {
	/**
	 * 转换dip为px(int)
	 * 
	 * @param context
	 * @param dip
	 * @return
	 */
	public static int dipToInt(Context context, int dip) {
		float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dip * scale + 0.5f * (dip >= 0 ? 1 : -1));
	}

	/**
	 * 转换px(int)为dip
	 * 
	 * @param context
	 * @param px
	 * @return
	 */
	public static int intToDip(Context context, int px) {
		float scale = context.getResources().getDisplayMetrics().density;
		return (int) (px / scale + 0.5f * (px >= 0 ? 1 : -1));
	}
}
